package org.qloudgen.borg.result;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.qloudgen.borg.CommonValues;

import com.google.common.collect.Maps;

public class DataShowOperator extends AbstractResultOperator{
	
	public DataShowOperator(List<Map<String, String>> list) {
		super(list);
	}

	@Override
	protected void doResult(ResultSet res) throws SQLException {
		
		ResultSetMetaData meta= res.getMetaData();
		Map<String,String> map ;
		int i = 0;
		
		int limit = CommonValues.getLimitRows();
		
		while(res.next()){
			 i++;
			 map = Maps.newHashMap();
			 map.put("row", String.valueOf(i));
			 for(int j=1;j<=meta.getColumnCount();j++)  {
				 
				 map.put(meta.getColumnName(j), res.getString(j));
				 
			 } 
			 this.list.add(map);
			 
			 if (i >= limit) break;
		}
	}
	
}
